﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace guest_management_in_a_hotel
{
    public partial class FrmTimKiemKhach : Form
    {
        SqlConnection conn;
        SqlCommand cmd;
        SqlDataAdapter da;
        DataSet ds;
        public static string CMND;
        public FrmTimKiemKhach()
        {
            InitializeComponent();
        }

        private void btntkKHsophong_Click(object sender, EventArgs e)
        {
            int tkkhach_sophong = Int32.Parse(tbtkKHsophong.Text);
            try
            {
                conn = Connect.getConnection();
                conn.Open();
                String strSql = "select TblGuests.Guest_Name[Họ và tên],TblGuests.Guest_Sex[Giới Tính],TblGuests.Guest_Passport_No[Số CMND],TblGuests.Guest_DOB[Ngày sinh],TblGuests.Guest_Address[Địa chỉ],TblGuests.Guest_Nationality[Quốc tịch],TblReserve.Room_Number[Phòng đang thuê] from TblGuests,TblReserve where TblReserve.Room_Number like '%" + tkkhach_sophong + "%' and TblReserve.Guest_Passport_No=TblGuests.Guest_Passport_No";
                cmd = new SqlCommand(strSql, conn);
                da = new SqlDataAdapter(cmd);
                ds = new DataSet();
                da.Fill(ds, "phong");
                dgvtimkiemkhach.DataSource = ds.Tables[0];
                conn.Close();

            }
            catch (Exception ex)
            {
                MessageBox.Show("Error " + ex.Message);
            }

        }

        private void btntktenkh_Click(object sender, EventArgs e)
        {
            try
            {
                conn = Connect.getConnection();
                conn.Open();
                String strSql = "select Guest_Name[Họ và tên],Guest_Sex[Giới Tính],Guest_Passport_No[Số CMND],Guest_DOB[Ngày sinh],Guest_Address[Địa chỉ],Guest_Nationality[Quốc tịch] from TblGuests where TblGuests.Guest_Name like N'%" + tbTKtenKH.Text + "%'";
                cmd = new SqlCommand(strSql, conn);
                da = new SqlDataAdapter(cmd);
                ds = new DataSet();
                da.Fill(ds, "phong");
                dgvtimkiemkhach.DataSource = ds.Tables[0];
                conn.Close();

            }
            catch (Exception ex)
            {
                MessageBox.Show("Error " + ex.Message);
            }

        }

        private void btntkkh_CMND_Click(object sender, EventArgs e)
        {
            try
            {
                conn = Connect.getConnection();
                conn.Open();
                String strSql = "select Guest_Name[Họ và tên],Guest_Sex[Giới Tính],Guest_Passport_No[Số CMND],Guest_DOB[Ngày sinh],Guest_Address[Địa chỉ],Guest_Nationality[Quốc tịch] from TblGuests where TblGuests.Guest_Passport_No like '%" + Int32.Parse(tbtkKHcmnd.Text) + "%'";
                cmd = new SqlCommand(strSql, conn);
                da = new SqlDataAdapter(cmd);
                ds = new DataSet();
                da.Fill(ds, "phong");
                dgvtimkiemkhach.DataSource = ds.Tables[0];
                conn.Close();

            }
            catch (Exception ex)
            {
                MessageBox.Show("Error " + ex.Message);
            }
        }

        private void btntkKHngaysinh_Click(object sender, EventArgs e)
        {
            try
            {
                conn = Connect.getConnection();
                conn.Open();
                String strSql = "select Guest_Name[Họ và tên],Guest_Sex[Giới Tính],Guest_Passport_No[Số CMND],Guest_DOB[Ngày sinh],Guest_Address[Địa chỉ],Guest_Nationality[Quốc tịch] from TblGuests where TblGuests.Guest_DOB like '%" + DateTime.Parse(dtptkngaysinh.Text).ToShortDateString()+ "%'";
                cmd = new SqlCommand(strSql, conn);
                da = new SqlDataAdapter(cmd);
                ds = new DataSet();
                da.Fill(ds, "phong");
                dgvtimkiemkhach.DataSource = ds.Tables[0];
                conn.Close();

            }
            catch (Exception ex)
            {
                MessageBox.Show("Error " + ex.Message);
            }
        }

        private void btnquaylai_Click(object sender, EventArgs e)
        {
            FrmMain frmmain1 = new FrmMain();
            frmmain1.Show();
            this.Hide();
        }

        private void btnXemthongtin_Click(object sender, EventArgs e)
        {
            CMND = dgvtimkiemkhach.CurrentRow.Cells[2].Value.ToString();

            //    string quoctich= dgvQLKhach.CurrentRow.Cells[5].Value.ToString();
            // MessageBox.Show(CMND);
            FrmThongTinKH frmThongtinKH = new FrmThongTinKH();
            frmThongtinKH.Show();
            this.Hide();
        }
    }
}
